package ru.grpc.client.service;

import com.google.protobuf.Empty;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;
import ru.test.grpc.ProfileDescriptorOuterClass.ProfileDescriptor;
import ru.test.grpc.ProfileServiceGrpc;

import java.util.Iterator;

@Service
public class GrpcService {

    @GrpcClient("profile")
    private ProfileServiceGrpc.ProfileServiceBlockingStub profileStub;

    public void send() {

        Iterator<ProfileDescriptor> iterator = profileStub.serverStream(Empty.newBuilder().build());
        while (iterator.hasNext()) {
            ProfileDescriptor profileDescriptor = iterator.next();
            System.out.println(profileDescriptor.getName() + System.currentTimeMillis());
        }
    }

}
